/**
 * @file install.js
 * @author Alejandro Dario Simi
 * @date $Date: 2013-01-11 01:54:03 +0000 (Fri, 11 Jan 2013) $
 *
 * $Id: install.js 51 2013-01-11 01:54:03Z daemonraco@gmail.com $
 * $URL: http://wcomix.googlecode.com/svn/tags/wcomix-1.0-BETA1/install/install.js $
 */

// Creating tables of contents.
$(function(){
	$(".TableOfContents").each(function(){
		var level = 1;
		var list  = "<ul>";

		$("div.Section span.Title,div.Section span.SubTitle").each(function() {
			if($(this).attr('class') == "SubTitle") {
				switch(level) {
					case 1:
						level = 2;
						list += "<ul>";
				}
			}
			if($(this).attr('class') == "Title") {
				switch(level) {
					case 2:
						level = 1;
						list += "</ul>";
				}
			}
			list += "<li><a href=\"#" + $(this).text() + "\">" + $(this).text() + "</a></li>";
			$(this).html("<a name=\"" + $(this).text() + "\">" + $(this).text() + "</a> <sup><a href=\"#\">[back]</a></sup>");
		});

		list+= "</ul>";
		$(this).html(list);
	});
});

// Replacing pseudo-code
$(function(){
	$("body").html($("body").html()
		.replace(/\[OK:([^\]]*)\]/g,'<span class="Ok">$1</span>')
		.replace(/\[FL:([^\]]*)\]/g,'<span class="Failed">$1</span>')

		.replace(/\[VA:([^\]]*)\]/g,'<span class="Variable">$1</span>')
		.replace(/\{VA:([^\}]*)\}/g,'<span class="Variable">$1</span>')
	);
});

// Adding page title
$(function(){
	$("head title").text($("span.PageTitle").text());
	$("head").append('<link rel="icon" type="image/png" href="wcomix.png"/>');
});